#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# -------------------------------------------------------------------------------
# Name:         run.py
# Description:  简单的测试运行脚本
# Author:       
# Date:         
# -------------------------------------------------------------------------------

import subprocess
import sys
import os

def test_direct_run():
    """测试直接运行项目"""
    # 获取项目根目录
    project_root = os.path.dirname(os.path.abspath(__file__))
    main_script = os.path.join(project_root, 'main.py')
    
    # 测试运行帮助命令
    try:
        result = subprocess.run([sys.executable, main_script, '-h'], 
                              capture_output=True, text=True, timeout=10)
        if result.returncode == 0:
            print("✓ 直接运行测试成功")
            print("帮助信息:")
            print(result.stdout[:500] + "..." if len(result.stdout) > 500 else result.stdout)
            return True
        else:
            print("✗ 直接运行测试失败")
            print("错误输出:")
            print(result.stderr)
            return False
    except subprocess.TimeoutExpired:
        print("✗ 运行超时")
        return False
    except Exception as e:
        print(f"✗ 运行出错: {e}")
        return False

if __name__ == "__main__":
    print("测试 wxdump 直接运行功能...")
    success = test_direct_run()
    if success:
        print("\n🎉 测试通过！现在可以直接运行项目而无需安装。")
        print("使用方法:")
        print(f"  {sys.executable} main.py          # 启动UI界面")
        print(f"  {sys.executable} main.py -h       # 查看帮助")
        print(f"  {sys.executable} main.py info     # 获取微信信息")
    else:
        print("\n❌ 测试失败，请检查代码。")